﻿using Pay.Core;
using Pay.DTO;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Pay.Token.Controllers
{
    /// <summary>
    /// 消费
    /// </summary>
    [RoutePrefix("consume")]
    public class ConsumeController : BaseController
    {
        private IConsumeItemService _iConsumeItemService;
        public ConsumeController(IConsumeItemService iConsumeItemService)
        {
            _iConsumeItemService = iConsumeItemService;
        }

        /// <summary>
        /// App获得项目消费列表
        /// </summary>
        /// <returns></returns>
        [Route("get_consume_item_list"), HttpGet,AllowAnonymous]
        public ResultMessage<List<app_consume_item_dto>> GetConsumeItemList()
        {
            var result = _iConsumeItemService.AppGetConsumeItemList();
            if (!System.Web.HttpContext.Current.Request.Url.ToString().Contains(t_RequestMethod.token_url)) {
                result = result.Where(o => o.consume_type != (int)EConsumeItemType.DistributionMall && o.consume_type != (int)EConsumeItemType.BuyCourse).ToList();
            }
            return ResultToJson.Json(result);
        }
        /// <summary>
        /// App获得项目消费列表 version 2.0
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [Route("get_consume_item_list_v2"), HttpPost, AllowAnonymous]
        public ResultMessage<List<app_consume_item_dto>> GetConsumeItemListAppstore(ConsumeQuery query) {
            query.merchant_id = UserId;
            var result = _iConsumeItemService.AppGetConsumeItemList(query);
            if (!System.Web.HttpContext.Current.Request.Url.ToString().Contains(t_RequestMethod.token_url)) {
                result = result.Where(o => o.consume_type != (int)EConsumeItemType.DistributionMall && o.consume_type != (int)EConsumeItemType.BuyCourse).ToList();
            }
            return ResultToJson.Json(result);
        }
        /// <summary>
        /// App获得商品兑换 商品分页列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [Route("get_consume_product_page_list"), HttpGet,AllowAnonymous]
        public ResultMessage<PagedResult<app_consume_product_dto>> GetConsumeProductPageList([FromUri]PageQuery query)
        {
            var result = new PagedResult<app_consume_product_dto>() { rows = new List<app_consume_product_dto>(), page = query.page, size = query.size, total_result = 0 };
            //var result = _iConsumeItemService.AppConsumeProductPageList(query);
            return ResultToJson.Json(result);
        }

        /// <summary>
        /// 根据商品Id 获得商品
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [Route("get_comsume_product"), HttpGet]
        public ResultMessage<app_consume_product_dto> GetComsumeProduct([FromUri]consume_product_query model)
        {
            app_consume_product_dto result = null;
            //var result = _iConsumeItemService.AppGetComsumeProduct(model.product_id);
            return ResultToJson.Json(result);
        }

        /// <summary>
        /// 商品兑换
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [Route("exchange_product"), HttpPost]
        public ResultMessage<bool> ExchangeProduct([FromBody]exchange_product_model model)
        {
            var result = false;
            //var result = _iConsumeItemService.AppExchangeProduct(UserId, model.product_id, model.red_drill,model.ship_adress_id);
            return ResultToJson.Json(result);
        }


        /// <summary>
        /// 获得用户兑换列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [Route("get_user_exchange_product_his"), HttpGet]
        public ResultMessage<PagedResult<user_exchange_product_his_dto>> GetUserExchangeProductHis([FromUri]PageQuery model)
        {
            var result = _iConsumeItemService.AppGetUserExchangeProductHis(model, UserId);
            return ResultToJson.Json(result);
        }


    }
}
